package com.paradisecloudtech.vc.system.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.paradisecloudtech.vc.system.R;
import com.paradisecloudtech.vc.system.mvp.bean.ConfsBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ConfsAdapter extends RecyclerView.Adapter<ConfsAdapter.ViewHolder> {

    private List<ConfsBean.ResultBean.ConferencesBean> conferencesBeans;
    private Context context;

    public ConfsAdapter(List<ConfsBean.ResultBean.ConferencesBean> conferencesBeans, Context context) {
        this.conferencesBeans = conferencesBeans;
        this.context = context;
    }

    @Override

    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.fragment_confs_recycleview_item, null, true);
        ViewHolder holder = new ViewHolder(inflate);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.tvConfsItemConfname.setText(conferencesBeans.get(position).getDescription());
        holder.tvConfsItemConfnumber.setText(conferencesBeans.get(position).getConfnum());
        String pin = conferencesBeans.get(position).getPin();
        if (TextUtils.isEmpty(pin)) {
            holder.tvConfsItemConfpin.setText("PIN:" + "无密码");
        } else {
            holder.tvConfsItemConfpin.setText("PIN:" + pin);
        }
        String curLayout = conferencesBeans.get(position).getCurLayout();
        switch (curLayout) {
            case "allEqual":
                curLayout = "全等";
                break;

            case "allEqualQuarters":
                curLayout = "4分屏全等";
                break;

            case "allEqualNinths":
                curLayout = "9分屏全等";
                break;

            case "allEqualSixteenths":
                curLayout = "16分屏全等";
                break;

            case "allEqualTwentyFifths":
                curLayout = "25分屏全等";
                break;

            case "onePlusFive":
                curLayout = "1大5小";
                break;

            case "onePlusSeven":
                curLayout = "1大7小";
                break;

            case "onePlusNine":
                curLayout = "1大9小";
                break;

            case "onePlusN":
                curLayout = "1大自动排列小的";
                break;
        }
        holder.tvConfsItemLayout.setText(curLayout);

        if (conferencesBeans.get(position).getStatus() == 0) {
            holder.tvConfsItemState.setText(R.string.state_prepare);
        } else if (conferencesBeans.get(position).getStatus() == 1) {
            holder.tvConfsItemState.setText(R.string.state_ing);
        }
    }

    @Override
    public int getItemCount() {
        return conferencesBeans.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_confs_item_confname)
        TextView tvConfsItemConfname;
        @BindView(R.id.tv_confs_item_confnumber)
        TextView tvConfsItemConfnumber;
        @BindView(R.id.tv_confs_item_confpin)
        TextView tvConfsItemConfpin;
        @BindView(R.id.tv_confs_item_layout)
        TextView tvConfsItemLayout;
        @BindView(R.id.tv_confs_item_state)
        TextView tvConfsItemState;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}

